<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="身份证号" prop="idNumber">
        <el-input
          v-model="queryParams.idNumber"
          placeholder="请输入身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出生日期" prop="birthDate">
        <el-date-picker clearable
          v-model="queryParams.birthDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择出生日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="民族ID" prop="ethnicityId">
        <el-input
          v-model="queryParams.ethnicityId"
          placeholder="请输入民族ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="政治面貌ID" prop="politicalStatusId">
        <el-input
          v-model="queryParams.politicalStatusId"
          placeholder="请输入政治面貌ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="外语语言ID" prop="foreignLanguageId">
        <el-input
          v-model="queryParams.foreignLanguageId"
          placeholder="请输入外语语言ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专科院校ID" prop="vocationalCollegeId">
        <el-input
          v-model="queryParams.vocationalCollegeId"
          placeholder="请输入专科院校ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专科专业ID" prop="vocationalMajorId">
        <el-input
          v-model="queryParams.vocationalMajorId"
          placeholder="请输入专科专业ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="考生类型ID" prop="candidateTypeId">
        <el-input
          v-model="queryParams.candidateTypeId"
          placeholder="请输入考生类型ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系电话" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入联系电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="通知书邮寄地址" prop="address">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入通知书邮寄地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="通知书收件人" prop="recipientName">
        <el-input
          v-model="queryParams.recipientName"
          placeholder="请输入通知书收件人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="邮编" prop="postalCode">
        <el-input
          v-model="queryParams.postalCode"
          placeholder="请输入邮编"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="考点盟市ID" prop="examCenterCityId">
        <el-input
          v-model="queryParams.examCenterCityId"
          placeholder="请输入考点盟市ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报考专业ID" prop="examMajorId">
        <el-input
          v-model="queryParams.examMajorId"
          placeholder="请输入报考专业ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="志愿院校ID" prop="volunteerCollegeId">
        <el-input
          v-model="queryParams.volunteerCollegeId"
          placeholder="请输入志愿院校ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="志愿专业ID" prop="volunteerMajorId">
        <el-input
          v-model="queryParams.volunteerMajorId"
          placeholder="请输入志愿专业ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['exam_candidate:exam_candidate:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['exam_candidate:exam_candidate:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['exam_candidate:exam_candidate:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['exam_candidate:exam_candidate:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="exam_candidateList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="考生ID" align="center" prop="id" />
      <el-table-column label="身份证号" align="center" prop="idNumber" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="性别" align="center" prop="gender" />
      <el-table-column label="出生日期" align="center" prop="birthDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.birthDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="民族ID" align="center" prop="ethnicityId" />
      <el-table-column label="政治面貌ID" align="center" prop="politicalStatusId" />
      <el-table-column label="外语语言ID" align="center" prop="foreignLanguageId" />
      <el-table-column label="专科院校ID" align="center" prop="vocationalCollegeId" />
      <el-table-column label="专科专业ID" align="center" prop="vocationalMajorId" />
      <el-table-column label="考生类型ID" align="center" prop="candidateTypeId" />
      <el-table-column label="联系电话" align="center" prop="phone" />
      <el-table-column label="通知书邮寄地址" align="center" prop="address" />
      <el-table-column label="是否未获得证书" align="center" prop="isCertificateIssued" />
      <el-table-column label="通知书收件人" align="center" prop="recipientName" />
      <el-table-column label="邮编" align="center" prop="postalCode" />
      <el-table-column label="考点盟市ID" align="center" prop="examCenterCityId" />
      <el-table-column label="报考专业ID" align="center" prop="examMajorId" />
      <el-table-column label="志愿院校ID" align="center" prop="volunteerCollegeId" />
      <el-table-column label="志愿专业ID" align="center" prop="volunteerMajorId" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['exam_candidate:exam_candidate:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['exam_candidate:exam_candidate:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改考生信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="身份证号" prop="idNumber">
          <el-input v-model="form.idNumber" placeholder="请输入身份证号" />
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="出生日期" prop="birthDate">
          <el-date-picker clearable
            v-model="form.birthDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择出生日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="民族ID" prop="ethnicityId">
          <el-input v-model="form.ethnicityId" placeholder="请输入民族ID" />
        </el-form-item>
        <el-form-item label="政治面貌ID" prop="politicalStatusId">
          <el-input v-model="form.politicalStatusId" placeholder="请输入政治面貌ID" />
        </el-form-item>
        <el-form-item label="外语语言ID" prop="foreignLanguageId">
          <el-input v-model="form.foreignLanguageId" placeholder="请输入外语语言ID" />
        </el-form-item>
        <el-form-item label="专科院校ID" prop="vocationalCollegeId">
          <el-input v-model="form.vocationalCollegeId" placeholder="请输入专科院校ID" />
        </el-form-item>
        <el-form-item label="专科专业ID" prop="vocationalMajorId">
          <el-input v-model="form.vocationalMajorId" placeholder="请输入专科专业ID" />
        </el-form-item>
        <el-form-item label="考生类型ID" prop="candidateTypeId">
          <el-input v-model="form.candidateTypeId" placeholder="请输入考生类型ID" />
        </el-form-item>
        <el-form-item label="联系电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入联系电话" />
        </el-form-item>
        <el-form-item label="通知书邮寄地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入通知书邮寄地址" />
        </el-form-item>
        <el-form-item label="通知书收件人" prop="recipientName">
          <el-input v-model="form.recipientName" placeholder="请输入通知书收件人" />
        </el-form-item>
        <el-form-item label="邮编" prop="postalCode">
          <el-input v-model="form.postalCode" placeholder="请输入邮编" />
        </el-form-item>
        <el-form-item label="考点盟市ID" prop="examCenterCityId">
          <el-input v-model="form.examCenterCityId" placeholder="请输入考点盟市ID" />
        </el-form-item>
        <el-form-item label="报考专业ID" prop="examMajorId">
          <el-input v-model="form.examMajorId" placeholder="请输入报考专业ID" />
        </el-form-item>
        <el-form-item label="志愿院校ID" prop="volunteerCollegeId">
          <el-input v-model="form.volunteerCollegeId" placeholder="请输入志愿院校ID" />
        </el-form-item>
        <el-form-item label="志愿专业ID" prop="volunteerMajorId">
          <el-input v-model="form.volunteerMajorId" placeholder="请输入志愿专业ID" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listExam_candidate, getExam_candidate, delExam_candidate, addExam_candidate, updateExam_candidate } from "@/api/exam_candidate/exam_candidate";

export default {
  name: "Exam_candidate",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 考生信息表格数据
      exam_candidateList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        idNumber: null,
        name: null,
        gender: null,
        birthDate: null,
        ethnicityId: null,
        politicalStatusId: null,
        foreignLanguageId: null,
        vocationalCollegeId: null,
        vocationalMajorId: null,
        candidateTypeId: null,
        phone: null,
        address: null,
        isCertificateIssued: null,
        recipientName: null,
        postalCode: null,
        examCenterCityId: null,
        examMajorId: null,
        volunteerCollegeId: null,
        volunteerMajorId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        idNumber: [
          { required: true, message: "身份证号不能为空", trigger: "blur" }
        ],
        name: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
        gender: [
          { required: true, message: "性别不能为空", trigger: "blur" }
        ],
        birthDate: [
          { required: true, message: "出生日期不能为空", trigger: "blur" }
        ],
        ethnicityId: [
          { required: true, message: "民族ID不能为空", trigger: "blur" }
        ],
        politicalStatusId: [
          { required: true, message: "政治面貌ID不能为空", trigger: "blur" }
        ],
        foreignLanguageId: [
          { required: true, message: "外语语言ID不能为空", trigger: "blur" }
        ],
        vocationalCollegeId: [
          { required: true, message: "专科院校ID不能为空", trigger: "blur" }
        ],
        vocationalMajorId: [
          { required: true, message: "专科专业ID不能为空", trigger: "blur" }
        ],
        candidateTypeId: [
          { required: true, message: "考生类型ID不能为空", trigger: "blur" }
        ],
        phone: [
          { required: true, message: "联系电话不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询考生信息列表 */
    getList() {
      this.loading = true;
      listExam_candidate(this.queryParams).then(response => {
        this.exam_candidateList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        idNumber: null,
        name: null,
        gender: null,
        birthDate: null,
        ethnicityId: null,
        politicalStatusId: null,
        foreignLanguageId: null,
        vocationalCollegeId: null,
        vocationalMajorId: null,
        candidateTypeId: null,
        phone: null,
        address: null,
        isCertificateIssued: null,
        recipientName: null,
        postalCode: null,
        examCenterCityId: null,
        examMajorId: null,
        volunteerCollegeId: null,
        volunteerMajorId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加考生信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getExam_candidate(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改考生信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateExam_candidate(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addExam_candidate(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除考生信息编号为"' + ids + '"的数据项？').then(function() {
        return delExam_candidate(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('exam_candidate/exam_candidate/export', {
        ...this.queryParams
      }, `exam_candidate_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
